﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using LitJson;

public class EnemyMsg {
	public int id;
	public string prefab;
	public EnemyMsg(){
		id = 0;
		prefab = "";
	}
}

public class EnemyConfig : MonoBehaviour {

	public TextAsset txtAssetFile;
	public List<EnemyMsg> enemyMsg_list;

	// Use this for initialization
	void Start () {
		enemyMsg_list = new List<EnemyMsg> ();
		parserEnemys ();
	}
	
	// Update is called once per frame
	void Update () {
	
	}

	void parserEnemys(){
		JsonData jsonData = JsonMapper.ToObject (txtAssetFile.text);
		
		JsonData jsonEnemys = jsonData ["Enemys"];
		for(int i = 0; i< jsonEnemys.Count; i++){
			JsonData jsonEnemy = jsonEnemys[i];
			int enemyId = int.Parse( jsonEnemy["id"].ToString());
			string enemyPrefab = jsonEnemy["prefab"].ToString();

			EnemyMsg enemyMsg = new EnemyMsg();
			enemyMsg.id = enemyId;
			enemyMsg.prefab = enemyPrefab;

			enemyMsg_list.Add(enemyMsg);
		}
	}

	public EnemyMsg getEnemyMsgById(int enemyId){
		EnemyMsg msgRet = null;
		for(int i=0; i<enemyMsg_list.Count; i++){
			EnemyMsg enemyMsg = enemyMsg_list[i];
			if(enemyMsg.id == enemyId){
				msgRet = enemyMsg;
				break;
			}
		}
		return msgRet;
	}
	
}



